<HTML>
 
<!-- Mirrored from www.javapractices.com/apps/movies/javadoc/src-html/hirondelle/movies/edit/MovieActionDelete.html by HTTrack Website Copier/3.x [XR&CO'2010], Sun, 12 Jun 2011 17:30:20 GMT -->
<HEAD>
  <TITLE>
MovieActionDelete.java
  </TITLE>
  <LINK REL ='stylesheet' TYPE='text/css' HREF='../../../../highlight.css' TITLE='Style'>
 </HEAD>
 <BODY>
<PRE>
<span class='keyword'>package</span> hirondelle.movies.edit;<a name=line.1></a>
<a name=line.2></a>
<span class='keyword'>import</span> hirondelle.movies.main.MainWindow;<a name=line.3></a>
<span class='keyword'>import</span> hirondelle.movies.util.Util;<a name=line.4></a>
<span class='keyword'>import</span> java.awt.event.ActionEvent;<a name=line.5></a>
<span class='keyword'>import</span> java.awt.event.KeyEvent;<a name=line.6></a>
<span class='keyword'>import</span> java.util.logging.Logger;<a name=line.7></a>
<span class='keyword'>import</span> javax.swing.AbstractAction;<a name=line.8></a>
<span class='keyword'>import</span> javax.swing.JTable;<a name=line.9></a>
<a name=line.10></a>
<span class='comment'>/**<a name=line.11></a>
  Delete the selected {@link Movie}.<a name=line.12></a>
  <a name=line.13></a>
  &lt;P&gt;This &lt;tt&gt;Action&lt;/tt&gt; is an example of an &lt;tt&gt;Action&lt;/tt&gt; that is enabled <a name=line.14></a>
  only under certain circumstances. This &lt;tt&gt;Action&lt;/tt&gt; is enabled only when the <a name=line.15></a>
  table has a row selected. Otherwise, it is disabled.<a name=line.16></a>
*/</span><a name=line.17></a>
<span class='keyword'>public</span> <span class='keyword'>class</span> MovieActionDelete  <span class='keyword'>extends</span> AbstractAction {<a name=line.18></a>
<a name=line.19></a>
  <span class='comment'>/** Constructor. */</span><a name=line.20></a>
  <span class='keyword'>public</span> MovieActionDelete(JTable aTable, MovieTableModel aMovieTableModel){<a name=line.21></a>
    <span class='keyword'>super</span>(<span class='literal'>"Delete"</span>, <span class='keyword'>null</span> );<a name=line.22></a>
    putValue(SHORT_DESCRIPTION, <span class='literal'>"Delete the selected movie"</span>); <a name=line.23></a>
    putValue(MNEMONIC_KEY, <span class='keyword'>new</span> Integer(KeyEvent.VK_D) );<a name=line.24></a>
    fTable = aTable;<a name=line.25></a>
    fMovieTableModel = aMovieTableModel;<a name=line.26></a>
    setEnabled(<span class='keyword'>false</span>);<a name=line.27></a>
  }<a name=line.28></a>
  <a name=line.29></a>
  <span class='comment'>/** Delete the {@link Movie} currently selected in the table. */</span><a name=line.30></a>
  <span class='keyword'>public</span> <span class='keyword'>void</span> actionPerformed(ActionEvent aActionEvent) {<a name=line.31></a>
    <span class='keyword'>int</span> row = fTable.getSelectedRow();<a name=line.32></a>
    Movie selectedMovie = fMovieTableModel.getMovie(row);<a name=line.33></a>
    fLogger.config(<span class='literal'>"Deleting the selected movie: "</span> + selectedMovie);<a name=line.34></a>
    MovieDAO dao = <span class='keyword'>new</span> MovieDAO();<a name=line.35></a>
    dao.delete(selectedMovie.getId());<a name=line.36></a>
    setEnabled(<span class='keyword'>false</span>); <span class='comment'>//this action is now over<a name=line.37></a>
</span>    MainWindow.getInstance().refreshView();<a name=line.38></a>
  }<a name=line.39></a>
  <a name=line.40></a>
  <span class='comment'>// PRIVATE //<a name=line.41></a>
</span>  <span class='keyword'>private</span> JTable fTable;<a name=line.42></a>
  <span class='keyword'>private</span> MovieTableModel fMovieTableModel;<a name=line.43></a>
  <span class='keyword'>private</span> <span class='keyword'>static</span> <span class='keyword'>final</span> Logger fLogger = Util.getLogger(MovieActionAdd.<span class='keyword'>class</span>);<a name=line.44></a>
}<a name=line.45></a>
 <a name=line.46></a>
</PRE><a name=line.47></a>
 </BODY><a name=line.48></a>
<HTML><a name=line.49></a>
